const http = require('http')
const url = require('url')

// let url_str = 'http://www.baidu.com:80/abc/index.html?name=zx&age=10#xxx'
// console.log(url.parse(url_str))          url.parse() 解析url数据
const server = http.createServer()
server.on('request', (req, res) => {
    urlObj = url.parse(req.url)
    res.writeHead(200,{
        'Content-Type':'text/html;charset=utf-8'
    })
    switch(urlObj.pathname){
        case '/':
            res.write('<h1>首页内容</h1>')
            break;
        case '/user':
            res.write('<h1>用户页</h1>')
            break;
        default:
            res.write('<h1>页面不在了...</h1>')
            break;
    }
    res.end()
})

server.listen(3000, 'localhost')